package com.ha7419x.rest;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class UploadRest {


    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    @HystrixCommand(fallbackMethod = "uploadFallBack") //如果当前调用的 get 方法出错了 则调用 fallback
    public Object upload(@RequestParam("photo") MultipartFile photo){
        if(photo != null){
            System.out.println("【**** UploadRest ***】文件名称"
                    + photo.getOriginalFilename() + " 、文件大小" + photo.getSize());
        }
        return "demo-file-" + System.currentTimeMillis() + ".jps";
    }

    public String uploadFallBack(@RequestParam("photo") MultipartFile photo){
       return "nophoto.jsp";
    }

}
